package com.qch;

import com.qch.bean.ConsumerComponet;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;

/**
 * @Author qch
 * @Date 2021/2/15
 */
public class AnnotationConsumerMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext configApplicationContext=new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        configApplicationContext.start();
        //获取消费者组件
        /**
         * 从Spring容器中拿组件，利用@Reference标注把远程的实现类组件生成一个代理
         */
        ConsumerComponet service = configApplicationContext.getBean(ConsumerComponet.class);
        while (true)
        {
            /*for (int i = 0; i <1000 ; i++) {
                Thread.sleep(5);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        String jhh = service.sayHello("request",0);
                        System.out.println("结果:"+jhh);
                    }
                }).start();
            }*/
            System.in.read();
           // String jhh = service.sayHello("haha111",0);
            String methodA = service.methodA("methodA", 0);
            System.out.println("结果"+methodA);
        }
    }
    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "com.qch.bean")
    @EnableDubbo
    static class ConsumerConfiguration{

    }
}
